fix: [SDK-4782] export package metadata for Capacitor discovery - #35
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
@claude review once |
There was a problem hiding this comment.
LGTM — adding ./package.json to the exports map is the standard fix for letting Capacitor's CLI discover plugin metadata when an exports field is present.
Extended reasoning...
Overview
The substantive SDK change is a single addition to package.json's exports map: "./package.json": "./package.json". Everything else (~80 files) is a non-shipping Nx/pnpm reproduction fixture under examples/demo-nx/ used to validate the fix against the reporter's environment.
Security risks
None. This only exposes the already-public package.json manifest through the package's exports map. No code, auth, crypto, or permission surface is touched. The fixture lives under examples/ and is not published (the files field in package.json restricts what ships).
Level of scrutiny
Low. This is a well-known Node.js convention — once a package declares an exports map, deep-path require.resolve calls (used by Capacitor CLI for plugin discovery) must be explicitly allowed. The pattern is documented in Node's resolution algorithm and is the standard remedy for tools that resolve sibling package.json paths.
Other factors
The reported nit is documentation-only on the example fixture's README (it describes pre-fix expectations while the committed generated files are post-fix). It does not affect SDK consumers and is fine to land as-is or address in a follow-up. PR description thoroughly explains motivation (issue #34), validation steps, and confirms both Android (capacitor.settings.gradle) and iOS (Package.swift) generated files now reference OneSignal.
Description
One Line Summary
Export package metadata so Capacitor can discover the plugin in pnpm/Nx monorepos.
Details
Motivation
Issue #34 reported that
@onesignal/capacitor-pluginwas skipped bycap syncwhen installed in a pnpm project. The reporter later provided an Nx monorepo reproduction where the Capacitor app lives underapps/shop, dependencies are declared at the workspace root, and Capacitor detects@capawesome/capacitor-app-updatebut not@onesignal/capacitor-plugin.In that layout, Capacitor resolves plugin package metadata from the app workspace. Packages without an
exportsmap allowrequire.resolve('<package>/package.json'), but our package export map did not expose./package.json, so the metadata lookup failed and Capacitor skipped the plugin.Scope
This PR adds
./package.jsonto the package export map. It does not change the runtime JS entrypoint, native Android/iOS sources, or public SDK APIs.Reproduction And Validation
Added
examples/demo-nx, a minimal Nx-style pnpm workspace matching the reporter's structure:@capawesome/capacitor-app-updateand@onesignal/capacitor-plugin.apps/shopwith no app-localpackage.json.Before the package metadata export fix,
cap syncfound only Capawesome. After packing this branch and installing the local tarball inexamples/demo-nx,cap syncfinds both plugins for Android and iOS.Testing
Unit testing
No unit tests were added because this is package metadata used by Capacitor CLI discovery rather than runtime SDK behavior.
Manual testing
vp packvp check package.json vite.config.tsvp test runvp pm pack, installed it intoexamples/demo-nxviafile:../../onesignal-capacitor-plugin.tgz, and ranCOREPACK_ENABLE_STRICT=0 npx pnpm@10.33.0 run sync.@capawesome/capacitor-app-updateand@onesignal/capacitor-plugin:apps/shop/android/capacitor.settings.gradleapps/shop/android/app/capacitor.build.gradleapps/shop/ios/App/CapApp-SPM/Package.swiftAffected code checklist
Checklist
Overview
Testing
Final pass
Made with Cursor